package com.atstudy.headline.web.admin.controller.sysOperationLog;

import com.atstudy.headline.entity.SysOperationLog;
import com.atstudy.headline.result.Result;
import com.atstudy.headline.web.admin.service.SysOperationLogService;
import com.atstudy.headline.web.admin.vo.sysOperationLog.LogDetailQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/sysOperationLog")
public class SysOperationLogController {
    @Autowired
    private SysOperationLogService sysOperationLogService;
    /**
     * 获取分页用户信息
     * @param
     * @return
     */
    @RequestMapping("/page")
    public Result<IPage<SysOperationLog>> pageLogDetail(@RequestParam Integer current, @RequestParam Integer size, LogDetailQueryVo queryVo) {
        Page<SysOperationLog> page = new Page<>();
        page.setCurrent(current);
        page.setSize(size);
        LambdaQueryWrapper<SysOperationLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like( queryVo.getOperatorId()!=null,SysOperationLog::getOperatorId,queryVo.getOperatorId() );
        queryWrapper.eq( queryVo.getDeptName()!=null,SysOperationLog::getDeptName,queryVo.getDeptName() );
        IPage<SysOperationLog> sysOperationLogIPage = sysOperationLogService.pageInfoBySysOperationLog(page, queryVo, 0); // 默认使用0作为占位符，实际应根据业务需求传递正确的操作员ID
        return Result.ok(sysOperationLogIPage);
    }

    /**
     * 新增日志信息或修改日志信息
     * @param
     * @return
     * @paramsystemOperationLog
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody SysOperationLog systemOperationLog) {
        sysOperationLogService.saveOrUpdate(systemOperationLog);
        return Result.ok();
    }

    /**
     * 删除日志信息
     * @param
     * @return
     */
    @RequestMapping("/delete")
    public Result delete(@RequestParam Integer logId) {
        sysOperationLogService.removeById(logId);
        return Result.ok();
    }
}
